--------------------------------------
-- Spell: Quick Etude
-- Enhances Agility of target party
-- member.
--------------------------------------
 
require("scripts/globals/settings");
require("scripts/globals/status");
require("scripts/globals/magic");

-----------------------------------------
-- OnSpellCast
-----------------------------------------

function OnMagicCastingCheck(caster,target,spell)
	return 0;
end;

function onSpellCast(caster,target,spell)
	local enchanceSkill = caster:getSkillLevel(40); -- Singing Skill
	local duration = 120;
	local power = 0;

	if(enchanceSkill <180)then
		power = 3
	elseif(enchanceSkill >=181 and enchanceSkill <=235)then
		power = 4
	elseif(enchanceSkill >=236 and enchanceSkill <=288)then
		power = 5
	elseif(enchanceSkill >=289 and enchanceSkill <=342)then
		power = 6
	elseif(enchanceSkill >=343 and enchanceSkill <=396)then
		power = 7
	elseif(enchanceSkill >=397 and enchanceSkill <=449)then
		power = 8
	elseif(enchanceSkill >=450)then
		power = 9
	else
		power = 10
	end

 	duration = duration + (duration * (caster:getMod(MOD_SONG_DURATION)/100));
	
	power = power + target:getMod(MOD_ETUDE) + target:getMod(MOD_ALL_SONGS);

	if (caster:hasStatusEffect(EFFECT_SOUL_VOICE)) then
		power = power * 2;
	elseif (caster:hasStatusEffect(EFFECT_MARCATO)) then
		power = power * 1.5;
	end
	caster:delStatusEffect(EFFECT_MARCATO);
    
	if (caster:hasStatusEffect(EFFECT_TROUBADOUR)) then
		duration = duration * 2;
	end

	if not (target:addBardSong(caster,EFFECT_ETUDE,power,0,duration,caster:getID(), 4, 1)) then
	        spell:setMsg(75);
	end

	return EFFECT_ETUDE;
end;